{% if NavUl is defined %}
    {{ NavUl }}
{% endif %}
{{ form('Res/examCharStat', 'method': 'post', 'class': 'form-group') }}
    <div class="form-inline">
        <label for="">题库：</label>
        {{ text_field('examId', 'class': 'form-control', 'placeholder': '数据中心ID号', 'style': 'width: 200px;') }}
        <label style="margin-left: 20px;">图片折算：</label>
        {{ numeric_field('imgCost', 'class': 'form-control', 'placeholder': '每张图代表字符', 'value': '20') }}
        <input type="submit" class="btn btn-success btn-sm" value="执行统计" style="width: 100px;margin-left: 20px;">
    </div>
{{ endform() }}
{% if tree is defined %}
    <table class="table table-striped">
        <tr class="info">
            <th style="width: 5%">
                <a class="btn btn-info btn-sm" onclick="getTotalCount()">计算</a>
            </th>
            <th style="width: 25%">目录名</th>
            <th style="width: 15%">题目数</th>
            <th style="width: 15%">字符数</th>
            <th style="width: 15%">字符数(去空格)</th>
            <th style="width: 15%">图片数</th>
            <th style="width: 15%">图片折合字符</th>
        </tr>
        {% for index,row in tree %}
            <tr>
                <td><label><input type="checkbox" class="charNum" data-index="{{ index }}" />选择</label></td>
                <td>{{ row['name'] }}</td>
                <td class="que" data-index="{{ index }}">{{ row['que'] }}</td>
                <td class="char" data-index="{{ index }}">{{ row['char'] }}</td>
                <td class="charReal" data-index="{{ index }}">{{ row['charReal'] }}</td>
                <td class="img" data-index="{{ index }}">{{ row['img'] }}</td>
                <td class="imgChar" data-index="{{ index }}">{{ row['imgChar'] }}</td>
            </tr>
        {% endfor %}
        <tr class="success">
            <td>
                <a class="btn btn-info btn-sm" onclick="getTotalCount()">计算</a>
            </td>
            <td>合计</td>
            <td>{{ total['que'] }}</td>
            <td>{{ total['char'] }}</td>
            <td>{{ total['charReal'] }}</td>
            <td>{{ total['img'] }}</td>
            <td>{{ total['imgChar'] }}</td>
        </tr>
    </table>
{% endif %}
<script>
    var checkDom;
    function getTotalCount() {
        checkDom = $('.charNum:checked');
        if (checkDom.length <= 0) {
            window.top.xhTop.showError('无选中记录');
            return false;
        }
        var que = 0,
            char = 0,
            charReal = 0,
            img = 0,
            imgChar = 0;
        $.each(checkDom, function (key, dom) {
            var index = $(dom).attr('data-index');
            que += parseInt($('.que[data-index='+ index +']').text());
            char += parseInt($('.char[data-index='+ index +']').text());
            charReal += parseInt($('.charReal[data-index='+ index +']').text());
            img += parseInt($('.img[data-index='+ index +']').text());
            imgChar += parseInt($('.imgChar[data-index='+ index +']').text());
        });
        var charRealImg = charReal + imgChar;
        window.top.swal({
            title: '小计',
            html: '题目数：' + que + '<br />' +
                '字符数：' + char + '<br />' +
                '字符数(去空格)：' + charReal + '<br />' +
                '图片数：' + img + '<br />' +
                '图片折合字符：' + imgChar + '<br />' +
                '字符数(去空格)+图片折合字符：' + charRealImg + '<br />',
            showConfirmButton: true
        });
    }
</script>